/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;


public class TaskGroup {
    private ArrayList<Task> taskGr;
    private String name;
    private String icon;
    
    public TaskGroup(String n, String icon){
        taskGr = new ArrayList();
        name = n;
        this.icon = icon;
    }

    public void add(Task t){
        taskGr.add(t);
            
    }
    public void removeAt(int index){
        
        taskGr.remove(index);
    }
    public Task getAt(int i){
        return taskGr.get(i);
    }
    
    public String getName(){
        return name;
    }
    public int getSize(){
        return taskGr.size();
    }

    public String getIcon(){
        return icon;
    }
    
    public ArrayList sortByStatus(){
        for(int i = 0; i < taskGr.size()-1; i++){
            for(int j = i+1; j < taskGr.size()-1; j++){
                if(taskGr.get(i).getStatus() > taskGr.get(j).getStatus()){
                    Task t = taskGr.get(i);
                    taskGr.set(i, taskGr.get(j));
                    taskGr.set(j, t);
                }
            }
        }
        return taskGr;
    }
    public ArrayList sortByTime(){
        for(int i = 0; i < taskGr.size()-1; i++){
            for(int j = i+1; j < taskGr.size()-1; j++){
                if(taskGr.get(i).getDateStart().before(taskGr.get(j).getDateStart())){
                    Task t = taskGr.get(i);
                    taskGr.set(i, taskGr.get(j));
                    taskGr.set(j, t);
                }
            }
        }
        return taskGr;
    }
    public ArrayList filterByName(String ten){
        ArrayList<Task> tg = new ArrayList();
        for(Task t : taskGr){
            if(t.getName().contains(ten)) tg.add(t);
        }
        return tg;
    }
    public ArrayList filterByPriority(int c){
        ArrayList<Task> tg = new ArrayList();
        for(Task t : taskGr){
            if(t.getPriority() == c) tg.add(t);
        }
        return tg;
    }
    
    
}
